package com.example.siyun.service.impl.couponsServerImp;


import com.example.siyun.mapper.couponsmapper.CouponsMapper;
import com.example.siyun.pojo.Coupons;
import com.example.siyun.service.couponsServer.CouponsServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

@Service
public class CouponsServerImp implements CouponsServer {

    @Autowired
    private CouponsMapper couponsMapper;

    /**
     * 添加优惠券
     * @param coupons
     * @return
     */
    @Override
    @Transactional
    public void addCoup(Coupons coupons) {
        couponsMapper.addCoup(coupons);
    }

    /**
     * 优惠券全部查询
     * @return
     */
    @Override
    @Transactional
    public List<Coupons> getCoup(String couponName,String couponManner,Integer couponRemainder) {
        return couponsMapper.getCoup(couponName,couponManner,couponRemainder);
    }

    /**
     * 优惠券列表中 用户增加未使用
     * @param userId
     * @param couponNoused
     * @param couponId
     * @return
     */
    @Override
    @Transactional
    public void giveCoup(Integer userId, Integer couponNoused, List<Integer> couponId) {
        couponsMapper.addNoused(userId,couponNoused);
        couponsMapper.decrRemainder(couponId);
    }

}
